#include "core/main.h"

bool ControllerState::operator==(const ControllerState &other) const 
{
    return state == other.state;
}

bool ControllerState::operator<(const ControllerState &other) const
{
    return state < other.state;
}

int ControllerState::BitFromKey(int key)
{
    switch(key)
    {
    case 'a':
        return leftBit;
    case 'd':
        return rightBit;
    case 'w':
        return upBit;
    case 's':
        return downBit;
    case 'k':
        return ABit;
    case 'l':
        return BBit;
    }
    return 0;
}

void ControllerState::KeyDown(int key)
{
    int bit = BitFromKey(key);
    if(bit == 0) return;
    state = state | bit;
}

void ControllerState::KeyUp(int key)
{
    int bit = BitFromKey(key);
    if(bit == 0) return;
    state = state & ~bit;
}

vector<ControllerState> ControllerState::getAllStates()
{
    vector<ControllerState> v;
    for (int state = 0; state < 0x1 << 6; state++) {
        ControllerState cs;
        cs.state = state;
        v.push_back(cs);
    }
    return v;
}

vector<ControllerState> ControllerState::getDirectionStates()
{
    vector<ControllerState> v;

    ControllerState none;
    v.push_back(none);

    ControllerState left;
    left.KeyDown('a');
    v.push_back(left);

    ControllerState right;
    right.KeyDown('d');
    v.push_back(right);

    ControllerState down;
    down.KeyDown('s');
    v.push_back(down);

    ControllerState up;
    up.KeyDown('w');
    v.push_back(up);

    return v;
}

vector<ControllerState> ControllerState::getLeftRightStates()
{
    vector<ControllerState> v;

    ControllerState none;
    v.push_back(none);

    ControllerState left;
    left.KeyDown('a');
    v.push_back(left);

    ControllerState right;
    right.KeyDown('d');
    v.push_back(right);

    return v;
}